home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000092_icon-group-sender_Thu Sep 18 12:43:42 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h8IJhEO27359
  4.     for icon-group-addresses; Thu, 18 Sep 2003 12:43:14 -0700 (MST)
  5. Message-Id: <200309181943.h8IJhEO27359@baskerville.CS.Arizona.EDU>
  6. X-Authentication-Warning: weaver.tuc.noao.edu: swampler set sender to swampler@noao.edu using -f
  7. Subject: Re: Simple Icon programming challenge...
  8. From: Steve Wampler <swampler@noao.edu>
  9. To: icon-group@cs.arizona.edu
  10. Date: Thu, 18 Sep 2003 07:52:29 -0700
  11. X-Spam-Status: No, hits=-8.2 required=5.0
  12.     tests=BAYES_10,IN_REP_TO,REFERENCES,USER_AGENT_XIMIAN,
  13.           X_AUTH_WARNING
  14.     version=2.55
  15. X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
  16. Errors-To: icon-group-errors@cs.arizona.edu
  17. Status: RO
  18.  
  19.  
  20. For the record, here are two possible solutions - the first
  21. is fairly straightforward, the second borders on the absurd...
  22. from the far side.  Both share a common ancestry and would be
  23. cleaner if rewritten to use William's scambleinnards(words)
  24. approach.
  25.  
  26. Solution 1:
  27.  
  28. ##################################################################
  29. # Scrambles words but leaves them 'readable' by fixing the first
  30. #    and last letters in place.
  31. #
  32. # Reads from standard input, writes to standard output
  33.  
  34. procedure main(args)
  35.     &random := integer(map("smhSMH","Hh:Mm:Ss",&clock))
  36.     while write(scrambleline(read()))
  37. end
  38.  
  39. # Take a single line of input and produce it's equivalent with
  40. #   interior letters of words scrambled.
  41. # Defines a word as any sequence of 1 or more letters, 
  42. #
  43. procedure scrambleline(line)
  44.     local s := ""
  45.     line ? {
  46.         while s ||:= tab(upto(&letters)) || sword(tab(many(&letters)))
  47.         return s || tab(0)
  48.         }
  49. end
  50.  
  51. # Do the actual scrambling of the word.  Note that words with less
  52. #   than four letters can't be scrambled (not enough interior letters)
  53. #
  54. procedure sword(word)
  55.     word ?:= (move(1) || scramble(tab(1<*word)) || move(1))
  56.     return word
  57. end
  58.  
  59. # This procedure just randomly rearranges the characters in its
  60. #   argument.
  61. #
  62. procedure scramble(s)
  63.     every !s :=: ?s
  64.     return s
  65. end
  66. #########################################################################
  67.  
  68. Solution 2 (unfit for human consumption!):
  69.  
  70. #########################################################################
  71. #### Scrambles words but leaves them 'readable' by fixing the first
  72. #    and last letters in place.
  73. #
  74. # Reads from standard input, writes to standard output
  75.  
  76. procedure main(args)
  77.     &random := integer(map("smhSMH","Hh:Mm:Ss",&clock))
  78.     while read() ? {
  79.         while writes(tab(upto(&letters))) do
  80.            (w := tab(many(&letters))\1) ?
  81.             writes(move(1), {s := tab(1<*w)|"";every !s :=: ?s; s},
  82. move(1)|"")
  83.         write(tab(0))
  84.         }
  85. end
  86. ######################################################################
  87.  
  88. -- 
  89. Steve Wampler -- swampler@noao.edu
  90. Quantum materiae materietur marmota monax si marmota
  91.                     monax materiam possit materiari?
  92.